//
//  AddTasksView.swift
//  Pomodoro
//
//  Created by zhengju on 2018/3/5.
//  Copyright © 2018年 zhengju. All rights reserved.
//

import UIKit

class AddTasksView: UIView {
    var doneAction: ((_ title: String)->())!
    var addField: UITextField!
    override init(frame: CGRect) {
        super.init(frame: frame)

        addField = UITextField.init(frame: CGRect.init(x: 20, y: 20, width: SCREEN_WIDTH - 40, height: 40))
        addField.placeholder = "添加新任务"
        addField.backgroundColor = UIColor.white
        addField.delegate = self
        addField.returnKeyType = .done
        self.addSubview(addField)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
extension AddTasksView: UITextFieldDelegate{
    func textFieldDidEndEditing(_ textField: UITextField) {//完成编辑
        
    }
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        guard textField.text?.count != 0 else { return false }
        if (doneAction != nil) {
            doneAction(textField.text!)
            textField.text = nil
        }
        return true
    }
}
